//
//  SystemMessageCell.m
//  sensen_ios
//
//  Created by 小贝 on 16/3/22.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "SystemMessageCell.h"
@interface SystemMessageCell()
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;//标题
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;//时间
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;//内容
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;

@end
@implementation SystemMessageCell

- (void)awakeFromNib {
    // Initialization code
    _bgView.layer.cornerRadius = 5.0;
}
#pragma mark--设置
- (void)setSystemModel:(SystemModel *)systemModel{
    _systemModel = systemModel;
    NSNumber *dateNub = [NSNumber numberWithFloat:[_systemModel.create_time floatValue]];
    NSDate *dateStr = [NSDate getDateFromeNumber:dateNub];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy年MM月dd日"];
    NSString *str=[ dateFormatter stringFromDate:dateStr];
    _timeLabel.text = str;
    _contentLabel.text = _systemModel.summary;
    _titleLabel.text = _systemModel.title;
    NSDictionary *dic = [self dictionaryWithJsonString:systemModel.extra];
    NSString *urlstr = [NSString stringWithFormat:@"%@%@",BOYE_PICTURE_URL,dic[@"image"]];
    NSURL *url = [NSURL URLWithString:urlstr];
    [_headImageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"defaultImage"]];
//    _contentLabel.text = [NSString stringWithFormat:@"就会多几个电话就过分很大功夫后果会很好过分很高的规范化肌肤感觉好机会环境规划%@",_systemModel.content];
}
#pragma mark---将字符串转换成字典
- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
    if (jsonString == nil) {
        return nil;
    }
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err) {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
